var http = require("http");
var url = require ("url");
var fs = require("fs");

var server = http.createServer(function (req, res) {
  var regex = new RegExp("^/Home/Index/?$");
  var pathname = url.parse(req.url).pathname;
  if(regex.test(pathname)){
  	res.writeHead(200, {"content-type": "text/html"});
	fs.readFile("./index.html", function(err, data){
		res.write(data);
		res.end();
	});
  }
  else {
   	res.writeHead(404, {"content-type": "text/plain"});
	res.end("File not found");
  }l
}).listen(8000, '127.0.0.1');
console.log('Server running at http://127.0.0.1:8000/');

var stocks = [];
 
stocks.push({name: "Healthy living", noOfShares:12000, shareValue: 3}); 
stocks.push({name: "Wild Life.cp", noOfShares: 12000, shareValue: 2});
stocks.push({name: "Casino gaming", noOfShares: 13000, shareValue: 4});
stocks.push({name: "Made for life", noOfShares: 10000, shareValue: 1});


var nowjs = require("now")
var everyone = nowjs.initialize(server);

nowjs.on( "connect", function(){
	// this.now.
	
	this.now.onConnected( stocks );
	
	///	everyone.now.DoStuff( ); - kallar í þetta fall hjá öllum clientum
	
});

everyone.now.distributeMessage = function(message){
	everyone.now.receiveMessage(this.now.name, message);
};


